package com.xuecheng.content.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.content.model.dto.*;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.CourseBaseInfoService;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.M
 * @version 1.0
 * @description 课程信息编辑接口
 * @date 2022/9/6 11:29
 */
@Api(value = "课程信息编辑接口",tags = "课程信息编辑接口")
@RestController
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseInfoService courseBaseInfoService;

    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams,
                                       @RequestBody QueryCourseParamsDto queryCourseParams){
        PageResult<CourseBase> pageResult = courseBaseInfoService.queryCourseBaseList(pageParams, queryCourseParams);
        return pageResult;
    }

    @ApiOperation("新增课程基础信息")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody AddCourseDto addCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseInfoService.createCourseBase(companyId,addCourseDto);
    }

    @ApiOperation("根据课程id查询课程基础信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseById(@PathVariable Long courseId){
        return courseBaseInfoService.getCourseBaseInfo(courseId);
    }

    @ApiOperation("修改课程基础信息")
    @PutMapping("/course")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated EditCourseDto editCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseInfoService.updateCourseBase(companyId,editCourseDto);
    }

    @ApiOperation(value = "查询教师信息", notes = "根据课程ID查询教师信息")
    @ApiImplicitParam(name = "courseId", value = "课程ID", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/courseTeacher/list/{courseId}")
    public List<CourseTeacherDto> listTeacherInfo(@PathVariable("courseId") Long courseId) {
        return courseTeacherService.selectTeacherList(courseId);
    }

    @ApiOperation(value = "添加教师信息", notes = "添加教师信息")
    @ApiImplicitParam(name = "teacherDto", value = "教师信息", required = true, dataType = "AddCourseTeacherDto", paramType = "body")
    @PostMapping("/courseTeacher")
    public CourseTeacherDto createTeacherInfo(@RequestBody @Validated({ValidationGroups.Inster.class}) AddCourseTeacherDto teacherDto) {
        // 获取用户所属机构的id
        Long companyId = 1232141425L;

        return courseTeacherService.insertTeacherInfo(teacherDto, companyId);
    }

    @ApiOperation(value = "删除教师信息", notes = "删除教师信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程id", required = true, dataType = "Long", paramType = "path"),
            @ApiImplicitParam(name = "courseTeacherId", value = "教师id", required = true, dataType = "Long", paramType = "path")
    })
    @DeleteMapping("/courseTeacher/course/{courseId}/{courseTeacherId}")
    public void deleteTeacherInfo(@PathVariable("courseId") Long courseId, @PathVariable Long courseTeacherId) {
        // 获取用户所属机构的id
        Long companyId = 1232141425L;

        courseTeacherService.deleteTeacherInfo(courseId, courseTeacherId, companyId);
    }

    @ApiOperation(value = "删除课程", notes = "删除课程")
    @DeleteMapping("/course/{id}")
    public void deleteCourseBase(@PathVariable Long id) {
        // 获取用户所属机构的id
        Long companyId = 1232141425L;
        courseBaseInfoService.deleteCourseBase(id, companyId);
    }
}